home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2000 July / CD 3 / redhat-6.2.iso / RedHat / instimage / usr / lib / anaconda / installclass.py < prev    next >
Encoding:
Python Source  |  2000-03-08  |  8.7 KB  |  303 lines

  1. # this is the prototypical class for workstation, server, and kickstart 
  2. # installs
  3. #
  4. # The interface to InstallClass is *public* -- ISVs/OEMs can customize the
  5. # install by creating a new derived type of this class.
  6.  
  7. # putting these here is a bit of a hack, but we can't switch between
  8. # newtfsedit and gnomefsedit right now, so we have to put up with this
  9. FSEDIT_CLEAR_LINUX  = (1 << 1)
  10. FSEDIT_CLEAR_ALL    = (1 << 2)
  11. FSEDIT_USE_EXISTING = (1 << 3)
  12.  
  13. import gettext_rh, os, iutil
  14. from xf86config import XF86Config
  15. from translate import _
  16.  
  17. class InstallClass:
  18.  
  19.     # look in mouse.py for a list of valid mouse names -- use the LONG names
  20.     def setMouseType(self, name, device = None, emulateThreeButtons = 0):
  21.     self.mouse = (name, device, emulateThreeButtons)
  22.  
  23.     def setLiloInformation(self, location, linear = 1, appendLine = None):
  24.     # this throws an exception if there is a problem
  25.     ["mbr", "partition", None].index(location)
  26.  
  27.     self.lilo = (location, linear, appendLine)
  28.  
  29.     def setClearParts(self, clear, warningText = None):
  30.     self.clearParts = clear
  31.         # XXX hack for install help text in GUI mode
  32.         if clear == FSEDIT_CLEAR_LINUX:
  33.             self.clearType = "wkst"
  34.         if clear == FSEDIT_CLEAR_ALL:
  35.             self.clearType = "svr"        
  36.     self.clearPartText = warningText
  37.  
  38.     def getLiloInformation(self):
  39.     return self.lilo
  40.  
  41.     def getFstab(self):
  42.     return self.fstab
  43.  
  44.     def addRaidEntry(self, mntPoint, raidDev, level, devices):
  45.     # throw an exception for bad raid levels
  46.     [ 0, 1, 5 ].index(level)
  47.     for device in devices:
  48.         found = 0
  49.         for (otherMountPoint, size, maxSize, grow, forceDevice) in \
  50.             self.partitions:
  51.         if otherMountPoint == device:
  52.             found = 1
  53.         if not found:
  54.         raise ValueError, "unknown raid device %s" % (device,)
  55.     if mntPoint[0] != '/' and mntPoint != 'swap':
  56.         raise ValueError, "bad raid mount point %s" % (mntPoint,)
  57.     if raidDev[0:2] != "md":
  58.         raise ValueError, "bad raid device point %s" % (raidDev,)
  59.     if level == 5 and len(devices) < 3:
  60.         raise ValueError, "raid 5 arrays require at least 3 devices"
  61.     if len(devices) < 2:
  62.         raise ValueError, "raid arrays require at least 2 devices"
  63.  
  64.     self.raidList.append(mntPoint, raidDev, level, devices)    
  65.  
  66.     def addNewPartition(self, mntPoint, size, maxSize, grow, device):
  67.     if not device: device = ""
  68.  
  69.     if mntPoint[0] != '/' and mntPoint != 'swap' and \
  70.         mntPoint[0:5] != "raid.":
  71.         raise TypeError, "bad mount point for partitioning: %s" % \
  72.             (mntPoint,)
  73.     self.partitions.append((mntPoint, size, maxSize, grow, device))
  74.  
  75.     def addToFstab(self, mntpoint, dev, fstype = "ext2" , reformat = 1):
  76.     self.fstab.append((mntpoint, (dev, fstype, reformat)))
  77.  
  78.     def setTimezoneInfo(self, timezone, asUtc = 0, asArc = 0):
  79.     self.timezone = (timezone, asUtc, asArc)
  80.  
  81.     def getTimezoneInfo(self):
  82.     return self.timezone
  83.  
  84.     def removeFromSkipList(self, type):
  85.     if self.skipSteps.has_key(type):
  86.         del self.skipSteps[type]
  87.  
  88.     def addToSkipList(self, type):
  89.     # this throws an exception if there is a problem
  90.     [ "lilo", "mouse", "network", "authentication", "complete", "complete",
  91.       "package-selection", "bootdisk", "partition", "format", "timezone",
  92.       "accounts", "dependencies", "language", "keyboard", "xconfig",
  93.       "welcome", "custom-upgrade", "installtype", "mouse", 
  94.       "confirm-install" ].index(type)
  95.     self.skipSteps[type] = 1
  96.  
  97.     def setHostname(self, hostname):
  98.     self.hostname = hostname
  99.  
  100.     def getHostname(self):
  101.     return self.hostname
  102.  
  103.     def setAuthentication(self, useShadow, useMd5, useNIS = 0, nisDomain = "",
  104.               nisBroadcast = 0, nisServer = ""):
  105.     self.auth = ( useShadow, useMd5, useNIS, nisDomain, nisBroadcast,
  106.               nisServer)
  107.  
  108.     def getAuthentication(self):
  109.     return self.auth
  110.  
  111.     def skipStep(self, step):
  112.     return self.skipSteps.has_key(step)
  113.  
  114.     def configureX(self, server, card, monitor, hsync, vsync, noProbe, startX):
  115.     self.x = XF86Config(mouse = None)
  116.     if (not noProbe):
  117.         self.x.probe()
  118.  
  119.     if not self.x.server:
  120.         self.x.setVidcard (card)
  121.  
  122.     if not self.x.monID and monitor:
  123.         self.x.setMonitor((monitor, (None, None)))
  124.     elif hsync and vsync:
  125.         self.x.setMonitor((None, (hsync, vsync)))
  126.  
  127.     if startX:
  128.         self.defaultRunlevel = 5
  129.  
  130.     # Groups is a list of group names -- the full list can be found in 
  131.     # ths comps file for each release
  132.     def setGroups(self, groups):
  133.     self.groups = groups
  134.  
  135.     def getGroups(self):
  136.     return self.groups
  137.  
  138.     # This is a list of packages -- it is combined with the group list
  139.     def setPackages(self, packages):
  140.     self.packages = packages
  141.  
  142.     def getPackages(self):
  143.     return self.packages
  144.  
  145.     def doRootPw(self, pw, isCrypted = 0):
  146.     self.rootPassword = pw
  147.     self.rootPasswordCrypted = isCrypted
  148.  
  149.     def getMakeBootdisk(self):
  150.     return self.makeBootdisk
  151.  
  152.     def setMakeBootdisk(self, state):
  153.     self.makeBootdisk = state 
  154.  
  155.     def setNetwork(self, bootproto, ip, netmask, gateway, nameserver):
  156.     self.bootProto = bootproto
  157.     self.ip = ip
  158.     self.netmask = netmask
  159.     self.gateway = gateway
  160.     self.nameserver = nameserver
  161.  
  162.     def setZeroMbr(self, state):
  163.     self.zeroMbr = state
  164.  
  165.     def getNetwork(self):
  166.     return (self.bootProto, self.ip, self.netmask, self.gateway, 
  167.         self.nameserver)
  168.  
  169.     def setEarlySwapOn(self, state = 0):
  170.     self.earlySwapOn = state
  171.  
  172.     def setLanguage(self, lang):
  173.     self.language = lang
  174.  
  175.     def setKeyboard(self, kb):
  176.     self.keyboard = kb
  177.  
  178.     def setPostScript(self, postScript, inChroot = 1):
  179.     self.postScript = postScript
  180.     self.postInChroot = inChroot
  181.  
  182.     def __init__(self):
  183.     self.skipSteps = {}
  184.     self.hostname = None
  185.     self.lilo = ("mbr", 1, "")
  186.     self.groups = None
  187.     self.packages = None
  188.     self.makeBootdisk = 0
  189.     self.timezone = None
  190.     self.setAuthentication(1, 1, 0)
  191.     self.rootPassword = None
  192.     self.rootPasswordCrypted = 0
  193.     self.installType = None
  194.     self.bootProto = None
  195.     self.ip = ""
  196.     self.netmask = ""
  197.     self.gateway = ""
  198.     self.nameserver = ""
  199.     self.partitions = []
  200.     self.clearParts = 0
  201.         self.clearType = None
  202.     self.clearText = None
  203.     self.clearPartText = None
  204.     self.zeroMbr = 0
  205.     self.language = None
  206.     self.keyboard = None
  207.     self.mouse = None
  208.     self.x = None
  209.     self.defaultRunlevel = None
  210.     self.postScript = None
  211.     self.postInChroot = 0
  212.     self.fstab = []
  213.     self.earlySwapOn = 0
  214.         self.desktop = ""
  215.     self.raidList = []
  216.  
  217.         if iutil.getArch () == "alpha":
  218.             self.addToSkipList("bootdisk")
  219.             self.addToSkipList("lilo")
  220.  
  221. # we need to be able to differentiate between this and custom
  222. class DefaultInstall(InstallClass):
  223.  
  224.     def __init__(self, expert):
  225.     InstallClass.__init__(self)
  226.  
  227. # custom installs are easy :-)
  228. class CustomInstall(InstallClass):
  229.  
  230.     def __init__(self, expert):
  231.     InstallClass.__init__(self)
  232.  
  233. # GNOME and KDE installs are derived from this
  234. class Workstation(InstallClass):
  235.  
  236.     def __init__(self, expert):
  237.     InstallClass.__init__(self)
  238.     self.setHostname("localhost.localdomain")
  239.     if not expert:
  240.         self.addToSkipList("lilo")
  241.     self.addToSkipList("authentication")
  242.     self.addToSkipList("package-selection")
  243.     self.setMakeBootdisk(1)
  244.  
  245.     if os.uname ()[4] != 'sparc64':
  246.         self.addNewPartition('/boot', 16, -1, 0, None)
  247.     self.addNewPartition('/', 700, -1, 1, None)
  248.     self.addNewPartition('swap', 64, -1, 0, None)
  249.     self.setClearParts(FSEDIT_CLEAR_LINUX, 
  250.         warningText = _("You are about to erase any preexisting Linux "
  251.                 "installations on your system."))
  252.  
  253. class GNOMEWorkstation(Workstation):
  254.  
  255.     def __init__(self, expert):
  256.     Workstation.__init__(self, expert)
  257.         self.desktop = "GNOME"
  258.     self.setGroups(["GNOME Workstation"])
  259.  
  260. class KDEWorkstation(Workstation):
  261.  
  262.     def __init__(self, expert):
  263.     Workstation.__init__(self, expert)
  264.         self.desktop = "KDE"
  265.     self.setGroups(["KDE Workstation"])
  266.  
  267. class Server(InstallClass):
  268.  
  269.     def __init__(self, expert):
  270.     InstallClass.__init__(self)
  271.     self.setGroups(["Server"])
  272.     self.setHostname("localhost.localdomain")
  273.     if not expert:
  274.         self.addToSkipList("lilo")
  275.     self.addToSkipList("package-selection")
  276.     self.addToSkipList("authentication")
  277.     self.setMakeBootdisk(1)
  278.  
  279.     if os.uname ()[4] != 'sparc64':
  280.         self.addNewPartition('/boot', 16, -1, 0, None)
  281.     self.addNewPartition('/', 256, -1, 0, None)
  282.     self.addNewPartition('/usr', 512, -1, 1, None)
  283.     self.addNewPartition('/var', 256, -1, 0, None)
  284.     self.addNewPartition('/home', 512, -1, 1, None)
  285.     self.addNewPartition('swap', 64, 256, 1, None)
  286.     self.setClearParts(FSEDIT_CLEAR_ALL, 
  287.         warningText = _("You are about to erase ALL DATA on your hard "
  288.                 "drive to make room for your Linux installation."))
  289.  
  290. # reconfig machine w/o reinstall
  291. class ReconfigStation(InstallClass):
  292.  
  293.     def __init__(self, expert):
  294.     InstallClass.__init__(self)
  295.     self.setHostname("localhost.localdomain")
  296.     self.addToSkipList("lilo")
  297.     self.addToSkipList("bootdisk")
  298.     self.addToSkipList("partition")
  299.     self.addToSkipList("package-selection")
  300.     self.addToSkipList("format")
  301.         self.addToSkipList("mouse")
  302.         self.addToSkipList("xconfig")
  303.